/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package converter;

import desk.WebClientController;
import ejb.Security;
import hibernate.User;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

/**
 * Конвертирует обьекты User
 * @author AGolubinskyy
 */
public class UserConverter extends AbstractConverter{
    private Security security;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Application app = context.getApplication();
        clientController = (WebClientController) app.evaluateExpressionGet(context, "#{webClientController}", WebClientController.class);
        security = clientController.getServerManager().getSecurity();
        return security.getUserByID(Integer.parseInt(value));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return Integer.toString(((User)value).getId());
    }

}
